package com.glodon.zhuanli.common;

import com.glodon.framework.web.util.ResponseParam;
import com.glodon.infrastructure.support.DefaultBaseController;
import com.glodon.zhuanli.ZLConstants;
import com.glodon.zhuanli.common.sms.ZLSMSService;
import com.glodon.zhuanli.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public abstract class ZhuanliBaseController extends DefaultBaseController {

    @Autowired
    protected SysUserService sysUserService ;

    @Autowired
    protected ZLSMSService zlsmsService ;

    /**
     * 获取登录用户的id
     * @return
     */
    public String getLoginUserId(){
        Object userId = getHttpServletRequest().getSession().getAttribute( ZLConstants.SESSION_USERID ) ;
        return userId==null ? null : userId.toString() ;
    }

    public ResponseParam buildEasyUIPageResult(List<?> resultList){
        ResponseParam responseParam = ResponseParam.success() ;
        //添加结果集对象
        responseParam.put( "rows" , resultList ) ;

        return responseParam ;
    }

    /**
     * 获取用户所属组织机构或企业的id
     * @return
     */
    public String getUserOrgIdOrCompanyId(){

        Object orgId = getHttpServletRequest().getSession().getAttribute( ZLConstants.SESSION_USER_ORGID ) ;

        Object companyId = getHttpServletRequest().getSession().getAttribute( ZLConstants.SESSION_USER_COMPANYID ) ;

        return orgId!=null ? orgId.toString() : companyId!=null ? companyId.toString() : null ;
    }

    public String getUserOrgId(){

        Object orgId = getHttpServletRequest().getSession().getAttribute( ZLConstants.SESSION_USER_ORGID ) ;

        return orgId!=null ? orgId.toString() : null ;
    }

    public String getUserCompanyId(){
        Object companyId = getHttpServletRequest().getSession().getAttribute( ZLConstants.SESSION_USER_COMPANYID ) ;

        return companyId!=null ? companyId.toString() : null ;
    }

}
